package com.oceansoft.mobile.biz.admin.controller;

import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.HtmlUtils;

import com.oceansoft.mobile.biz.admin.entity.NewsArticle;
import com.oceansoft.mobile.biz.admin.entity.SysUser;
import com.oceansoft.mobile.biz.admin.service.IApplyadminService;
import com.oceansoft.mobile.biz.front.entity.AppPlugins;
import com.oceansoft.mobile.biz.front.entity.AppPlugins_api;
import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.base.entity.Pager;
import com.oceansoft.mobile.common.base.entity.Query;
import com.oceansoft.mobile.common.base.entity.Result;
import com.oceansoft.mobile.common.util.UuidUtils;

@Controller
@RequestMapping("apply/admin")
public class ApplyAdminController {
	 @Resource
	 IApplyadminService applyadminService;
	/**
	 * 进入后台轻应用列表
	 * @param model
	 * @return
	 */
	 @RequestMapping(value = "apply-index", method = GET)
	 public String gotocountlList(Model model) {
	      return "admin/apply/apply_list";
	 }
	 @ResponseBody
	 @RequestMapping(value = "applyList", method = GET)
	 public Pager gotoCountList(HttpSession session, Query query, HttpServletRequest request) {
	      String keywords = request.getParameter("keywords");
	      return applyadminService.findApplyInfo(query, keywords);
	  }
	 /**
	     * 删除
	     *
	     * @return Result
	     */
	    @ResponseBody
	    @RequestMapping(value = "delNews", method = DELETE)
	    public Result deleteArticleById(HttpSession session, @RequestParam("id") int id) {
	    	applyadminService.deleteApplyById(id);
	        return new Result();
	    }
	    @RequestMapping(value = "gotoAdd", method = GET)
	    public String gotoArticleEdit(HttpSession session, @RequestParam(value = "id", required = false) int id, Model model) {
	    	AppPlugins apply=applyadminService.loadApplyById(id);
	       model.addAttribute("apply",apply);
	        return "admin/apply/apply_edit";
	    }
	    /**
	     * 表单提交（编辑）
	     *
	     * @return Result
	     */
	    @ResponseBody
	    @RequestMapping(value = "editApply", method = POST)
	    public Result submitProductForm(AppPlugins apply, HttpSession session, HttpServletRequest request) {
	       return applyadminService.saveOrUpdate(apply);
	    }
	    @RequestMapping(value = "gotoAddNew", method = GET)
	    public String gotoArticleAdd(HttpSession session, Model model) {
	        return "admin/apply/apply_add";
	    }
	    /**
	     * 表单提交（新增）
	     *
	     * @return Result
	     */
	    @ResponseBody
	    @RequestMapping(value = "addApply", method = POST)
	    public Result submitAddProductForm(AppPlugins apply, HttpSession session, HttpServletRequest request) {
	    	//apply.setId(54+Integer.parseInt(UuidUtils.getUpperUuid()));
	    	apply.setDescription(apply.getTitle());
	    	apply.setAppType(1);
	    	apply.setPage(apply.getStartPage());;
	    	apply.setPagesize(0);
	    	//apply.setOrdernum(apply.getId());
	       return applyadminService.saveApply(apply);
	    }
}
